package Apps;

import Dao.UntilHive;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LoadsData {
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;

    public void loadData(String filepath, String tableName){
        String sql = "load data local inpath '" + filepath + "' into table " + tableName;
        System.out.println("Running: " + sql);
        try {
            statement.execute(sql);
            System.out.println("加载成功！");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    public void close(){
        UntilHive.closeAll(connection, statement, resultSet);
    }

    public static void main(String[] args){
        LoadsData loadsData = new LoadsData();
        loadsData.connection = UntilHive.getCon();
        try {
            loadsData.statement = loadsData.connection.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        loadsData.loadData("/home/dataTrans/hive/a.txt", "u_data");
        loadsData.close();

    }
}
